
# 默认值参数
"""
1. 在定义时给某个参数设置一个默认值 ，若调用时不传入此参数值的话，它就会按默认值来 。print(self, *args, sep=' ', end='\n', file=None)
2. 设置默认值的格式是： key=value
3. 若参数中有默认值参数，必须放在正常参数后面
"""

def login(username,password='123456'):
    # 1. 定义一个用户
    db_username = 'admin'
    db_password = '123456'

    # 用户名或密码为空的情况，给出提示
    if username is None or username == "":
        return {"code":2,"message":"用户名不能为空!"}
    if password is None or password == "":
        return {"code":3,"message":"密码不能为空!"}

    # 2. 用户传入的用户名和密码和数据库进行比较，如果匹配了，登录成功，反之登录失败。
    if username == db_username and password == db_password:
        return {"code":1,"message":"登录成功"}

    # 3. 匹配失败的情况
    return {"code":4,"message":"登录失败"}


print(login('admin','1234567'))
print(login('admin'))

# 案例 ：12. 输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。要求返回的数据是以字典格式。
def char_stac(mystr):
    letter = 0
    space = 0
    number = 0
    other = 0
    dct = {'letter':letter,'space':space,'number':number,'other':other}
    for x in mystr:
        if x.isalpha():
            letter += 1
            continue
        if x.isdigit():
            number += 1
            continue
        if x.isspace():
            space += 1
            continue
        other += 1

    dct['letter'] = letter
    dct['space'] = space
    dct['number'] = number
    dct['other'] = other
    return dct

print(char_stac("FGHKJLK:%^%&* kdlksfljs  sjfklsdjflksjfsdfjs"))